package chan.module.project.hw.mrs.ck.v350.test;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MRSClickhouseV350TestByLocalMain {
    public static void main(String[] args) throws Exception {
        String driverName = "com.clickhouse.jdbc.ClickHouseDriver";
        String url = "jdbc:ch://10.10.93.63:8123/default";
        String user = "default";
        String password = "123456";
        // 1. 加载驱动
        Class.forName(driverName);
        Connection conn = DriverManager.getConnection(url, user, password);


        /*// 3. 创建Statement
        Statement stmt = conn.createStatement();
        // 4. 执行查询
        ResultSet rs = stmt.executeQuery("SELECT tuple_col FROM test_table_1");
        ResultSetMetaData metaData = rs.getMetaData();
        int columnCount = metaData.getColumnCount();
        List<String> names = new ArrayList<>(columnCount);
        for (int i = 1; i <= columnCount; i++) {
            names.add(metaData.getColumnName(i));
        }
        // 5. 处理结果
        while(rs.next()) {
            for (String name : names) {
                Object value = rs.getObject(name);
                System.out.println( name +":" + value);
            }
        }
        // 6. 释放资源
        rs.close();
        stmt.close();*/

        PreparedStatement statement = conn.prepareStatement("INSERT INTO test_table_2(int_col,tuple_col)");
        statement.setInt(1,123);
        List<Object> tuple_col = new ArrayList<>();
        tuple_col.add("asd");
        tuple_col.add(111111);
        tuple_col.add(1.2);
        statement.setObject(2,tuple_col);
        statement.execute();
        statement.close();

        conn.close();
    }
}
